package com.qiandw.handler;

import com.qiandw.entity.SysUser;
import com.qiandw.utils.RequestUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 关于HttpRequest请求判断
 * @author coxx
 */
@Slf4j
public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
        SysUser user = (SysUser) authentication.getPrincipal();
        log.info("管理员" + user.getRealName() + " 登录");
        log.info("IP" + RequestUtils.getIPAddress(request));
        super.onAuthenticationSuccess(request, response, authentication);
    }
}
